// var MapUtil = require('mapUtil');
var ClientNotify = {};
ClientNotify.callbackList = [];

ClientNotify.init = function() {
    ClientNotify.callbackList = new MapUtil();
    ClientNotify.callbackList.init();
}

ClientNotify.register = function(type, callback, target) {
    var isExist = ClientNotify.callbackList.contains(type);
    if (isExist) {
        var arr = ClientNotify.callbackList.get(type);
        arr.push([callback, target]);
    } else {
        var arr = new Array();
        arr.push([callback, target]);
        ClientNotify.callbackList.put(type, arr);

    }
}

ClientNotify.removeByTypeAndCallback = function(type, callback) {
    var isExist = ClientNotify.callbackList.contains(type);
    if (isExist) {
        var arr = ClientNotify.callbackList.get(type);
        for (var i = 0; i < arr.length; i++) {
            if (arr[i][0] == callback) {
                arr.splice(i, 1);
                return true;
            }
        }
        return false;
    }
    return false;
}

ClientNotify.removeByType = function(type) {
    var isExist = ClientNotify.callbackList.contains(type);
    if (isExist) {
        return ClientNotify.callbackList.remove(type);
    }
    return false;
}

ClientNotify.removeAll = function() {
    ClientNotify.callbackList.clear();
}

ClientNotify.send = function(type, obj) {
    var isExist = ClientNotify.callbackList.contains(type);
    if (isExist) {
        var arr = ClientNotify.callbackList.get(type);
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] != undefined && arr[i] != null) {
                arr[i][0](obj, arr[i][1]);
            }
        }
    }
}
window.ClientNotify = ClientNotify;


//全局方法
G.showTip = function(data){
    ClientNotify.send(CLIENT_NOTIFY_TYPE.TIP, data);
}

G.showTipPanel = function(data){
    ClientNotify.send(CLIENT_NOTIFY_TYPE.TIPPANEL, data);
}
window.G = G;